class Set { protected int n1,n2; public void setData(int x,int y) { n1=x; n2=y; } public int sum() { int s=n1+n2; return s; } public double mean() { double m=sum()/2.0; return m; } } class XSet extends Set { protected int n3; public void setData(int x,int y,int z) { setData(x,y); n3=z; } public int sum() { int s=super.sum()+n3; return s; } public double mean() { double m=sum()/3.0; return m; } } class demo { public static void main(String args[]) { Set a = new Set(); a.setData(4,5 ); System.out.println("Sum of set a is "+a.sum()); System.out.println("Mean of set a is "+a.mean()); XSet b=new XSet(); b.setData(1,2,4); System.out.println("Sum of set b is "+b.sum()); System.out.println("Mean of set b is "+ b.mean()); } }
Sum of set a is 9 Mean of set a is 4.5 Sum of set b is 7 Mean of set b is 2.333333
class person { private String name,city; public void setData(String nm,String ct) { name=nm; city=ct; } public void showData() { System.out.println("Name is "+name); System.out.println("City is "+city); } } class student extends person { private int rollno; public void setData(int rn,string nm,String ct) { setData(nm,ct); rollno=rn; } public void showData() { System.out.println("RollNo is "+rollno); super.showData(); } } class demo { public static void main(String args[]) { Person a =new Person(); a.setData("Amit","Amravati"); a.showData(); student b=new student(); b.setData(4117,"Nitin","Nagpur"); b.showData(); } }
Name is Amit City is Amravati RollNo is 4117 Name is Nitin City is Nagpur